<?php 
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
try{
	include '../../connection/connection_prenextcar.php';
	if($connection_prenextcar){
		include '../showscreen.php';
		set_time_limit(0);
		$CT = new showscreen();
		$winW = $_REQUEST['winW'];
		$winH = $_REQUEST['winH'];
		$vnumb=$_REQUEST['numb'];
		$idmo=$_REQUEST['idmo'];
		$vidcam=$_REQUEST['idcam'];
		$numb=1;
		$bd=$_REQUEST['bd'];
		$kt=$_REQUEST['kt'];
		$onewidth=$winW-6;
		$oneheight=($winH-120);
		if(isset($_REQUEST['type'])){
			if($_REQUEST['type']=='pre'){
				if(isset($_REQUEST['idcam']) && isset($_REQUEST['vtime'])){
					$query="SELECT configcamera.`name`,
					configcamera.`host`,carnum.car_datetime,
					carnum.carnumber,configcamera.lens_type,configcamera.camera_type,
					configcamera.trigger_type,carnum.id,carnum.filename,carnum.idx,
					monitor.timeOut 
					from configcamera,carnum,monitor 
					where carnum.id=configcamera.id 
					and carnum.id=".$_REQUEST['idcam']." and carnum.car_datetime < '".$_REQUEST['vtime']."' 
					and monitor.Monitor_ID=".$_REQUEST['idmo']." order by carnum.car_datetime desc limit 0,1";
					$selectpos = mysql_query($query,$connection_prenextcar);
					if(mysql_num_rows($selectpos)>0){
						while( $row=mysql_fetch_array($selectpos) ){
							$CT->Instanceview(chop($row['filename']), chop($row['host']), chop($row['car_datetime']), chop($row['camera_type']), chop($row['lens_type']), chop($row['name']), chop($row['id']), chop($row['trigger_type']), chop($row['timeOut']),chop($row['carnumber']),$row['idx']);
							$_SESSION['currentdownload'] = array($CT->id,$CT->name,$CT->car_datetime,$CT->platecar,$CT->host,$CT->filename,'');
							$_SESSION['onecarview']=$CT;
						}
					}else{
						$query="SELECT configcamera.`name`,
						configcamera.`host`,carnum.car_datetime,
						carnum.carnumber,configcamera.lens_type,configcamera.camera_type,
						configcamera.trigger_type,carnum.id,carnum.filename,carnum.idx,
						monitor.timeOut 
						from configcamera,carnum,monitor 
						where carnum.id=configcamera.id 
						and carnum.id=".$_REQUEST['idcam']." and carnum.car_datetime <= '".$_REQUEST['vtime']."' 
						and monitor.Monitor_ID=".$_REQUEST['idmo']." order by carnum.car_datetime desc limit 0,1";
						$selectpos = mysql_query($query,$connection_prenextcar);
						if(mysql_num_rows($selectpos)>0){
							while( $row=mysql_fetch_array($selectpos) ){
								$CT->Instanceview(chop($row['filename']), chop($row['host']), chop($row['car_datetime']), chop($row['camera_type']), chop($row['lens_type']), chop($row['name']), chop($row['id']), chop($row['trigger_type']), chop($row['timeOut']),chop($row['carnumber']),$row['idx']);
								$_SESSION['currentdownload'] = array($CT->id,$CT->name,$CT->car_datetime,$CT->platecar,$CT->host,$CT->filename,'');
								$_SESSION['onecarview']=$CT;
							}
						}
					}
					mysql_free_result($selectpos);
				}
			}else if($_REQUEST['type']=='next'){
				if(isset($_REQUEST['idcam']) && isset($_REQUEST['vtime'])){
					$query="SELECT configcamera.`name`,
					configcamera.`host`,carnum.car_datetime,
					carnum.carnumber,configcamera.lens_type,configcamera.camera_type,
					configcamera.trigger_type,carnum.id,carnum.filename,carnum.idx,
					monitor.timeOut 
					from configcamera,carnum,monitor 
					where carnum.id=configcamera.id 
					and carnum.id=".$_REQUEST['idcam']." and carnum.car_datetime > '".$_REQUEST['vtime']."' 
					and monitor.Monitor_ID=".$_REQUEST['idmo']." order by carnum.car_datetime asc limit 0,1";
					$selectpos = mysql_query($query,$connection_prenextcar);
					if(mysql_num_rows($selectpos)>0){
						while( $row=mysql_fetch_array($selectpos) ){
							$CT->Instanceview(chop($row['filename']), chop($row['host']), chop($row['car_datetime']), chop($row['camera_type']), chop($row['lens_type']), chop($row['name']), chop($row['id']), chop($row['trigger_type']), chop($row['timeOut']),chop($row['carnumber']),$row['idx']);
							$_SESSION['currentdownload'] = array($CT->id,$CT->name,$CT->car_datetime,$CT->platecar,$CT->host,$CT->filename,'');
							$_SESSION['onecarview']=$CT;
						}
					}else{
						$query="SELECT configcamera.`name`,
						configcamera.`host`,carnum.car_datetime,
						carnum.carnumber,configcamera.lens_type,configcamera.camera_type,
						configcamera.trigger_type,carnum.id,carnum.filename,carnum.idx,
						monitor.timeOut 
						from configcamera,carnum,monitor 
						where carnum.id=configcamera.id 
						and carnum.id=".$_REQUEST['idcam']." and carnum.car_datetime >= '".$_REQUEST['vtime']."' 
						and monitor.Monitor_ID=".$_REQUEST['idmo']." order by carnum.car_datetime asc limit 0,1";
						$selectpos = mysql_query($query,$connection_prenextcar);
						if(mysql_num_rows($selectpos)>0){
							while( $row=mysql_fetch_array($selectpos) ){
								$CT->Instanceview(chop($row['filename']), chop($row['host']), chop($row['car_datetime']), chop($row['camera_type']), chop($row['lens_type']), chop($row['name']), chop($row['id']), chop($row['trigger_type']), chop($row['timeOut']),chop($row['carnumber']),$row['idx']);
								$_SESSION['currentdownload'] = array($CT->id,$CT->name,$CT->car_datetime,$CT->platecar,$CT->host,$CT->filename,'');
								$_SESSION['onecarview']=$CT;
							}
						}
					}
					mysql_free_result($selectpos);
				}
			}
		}
		mysql_close($connection_prenextcar);
		$mfont=($onewidth / 50)."px";
		?>
		<input id="vonecarid" type="hidden" value="<?=$CT->idx?>" />
		<input id="vonecaridmo" type="hidden" value="<?=$idmo?>" />
		<input id="vonecaridcam" type="hidden" value="<?=$vidcam?>" />
		<table width="100%" height="88%" border="0" style="background:none; cellsapcing:5px;border-collapse: separate;" onmousedown="return false" onselectstart='return false;'>
			<tr>
				<td style="background-size:<?php echo $onewidth."px"?> <?php echo $oneheight."px"?>;background-repeat:no-repeat;">
					<div  id="<?php echo 'hinh'.($i+1)?>" ondblclick="loadContentHome(<?=$vnumb?>,<?=$bd?>,<?=$kt?>)" style="background-image:url('images/noimage.jpg') no-repeat center;background-size:<?php echo $onewidth."px"?> <?php echo $oneheight."px"?>;background-repeat:no-repeat;width:<?php echo $onewidth."px"?>;height:<?php echo $oneheight."px"?>;position:relative;">
						<div style="position:absolute;">
						<img src="<?=$CT->image?>" style='width:<?php echo $onewidth."px"?>;height:<?php echo $oneheight."px"?>;border: 1px solid #CFD6D9;border-radius: 2px;' onerror="this.src='images/noimage.jpg';" />
						</div>
						<div style="position:absolute;">
						<table style="background:none;padding:1%;width:<?php echo $onewidth."px"?>;height:<?php echo $oneheight."px"?>;" border="0">
							<tr>
								<td colspan="2" valign="top" >
									<table width="100%"  border="0" style="background:none;">
										<tr>
											<td align="left" valign="top"  style="color: yellow;font-size:<?php echo $mfont;?>;"><?php echo $CT->name?></td>
											<td align="right" valign="top">
												<?php if ($CT->light == 1) {?>
								              	<img src='images/circle-green.png' style='width:13px;height:13px;'>
								              	<?php }else if ($CT->light == 0){?>
								              		<img src='images/circle_red.png' style='width:13px;height:13px;'>
								              <?php }?>
											</td>
										</tr>
									</table>
								</td>
							<tr>
							<tr>
								<td valign="bottom" height="40%">
									<table width="100%" border="0" height="100%"  border="0" style="background:none;">
										<tr>
											<td align="left" width="50%" valign="bottom"><img src="images/pre1.png" onclick="view_prenext_car('pre',<?=$vnumb?>,<?=$CT->id?>,<?=$idmo?>,'<?=$CT->car_datetime?>',<?=$bd?>,<?=$kt?>);" style="cursor:pointer;padding-left:3%" /></td>
											<td align="right" width="50%" valign="bottom"><img src="images/next1.png" onclick="view_prenext_car('next',<?=$vnumb?>,<?=$CT->id?>,<?=$idmo?>,'<?=$CT->car_datetime?>',<?=$bd?>,<?=$kt?>);" style="cursor:pointer;padding-right:3%" /></td>
										</tr>
										<tr >
											<td colspan="2" align="right" valign="bottom"   style="color: yellow;font-size:<?php echo $mfont;?>;"><?=$CT->distance?></td>
										</tr>
										<tr >
											<td align="left" valign="middle"   style="color: yellow;font-size:<?php echo $mfont;?>;"><?=$CT->car_datetime?></td>
											<td align="right" valign="middle"  style="color: yellow;font-size:<?php echo $mfont;?>;"><?=$CT->vstriger_type?></td>
										<tr>
										<tr >
											<td colspan="2" valign="middle">
												<table width="100%"  border="0" style="background:none;">
													<tr>
														<td align="left" valign="bottom"  style="width:30%;color: yellow;font-size:<?php echo $mfont;?>;"><?=$CT->platecar?></td>
														<td align="center" valign="bottom"  style="width:40%;color: yellow;font-size:<?php echo $mfont;?>;">
															Width : <?=$onewidth?>
															Height : <?=$oneheight?>
														</td>
														<td align="center" valign="bottom" style="width:30%;color: yellow;font-size:<?php echo $mfont;?>;">
															<a href="download.php" style='color:#1268f8;font-size:<?=$mfont?>'>Download</a>
														</td>
													</tr>
												</table>
											</td>
										<tr>
										<tr>
											<td colspan="2" align="left" valign="bottom" style="color: yellow;font-size:<?php echo $mfont;?>;">Filename: <?=$CT->filename?></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
						</div>
					</div>
				</td>
			</tr>
		</table>
<?php 
	}else{
		echo "die";	
	}
}catch(Exception $e){
	echo $e->getMessage();
}
?>